const mgdb = require('../data/config')
const UserSchema = mgdb.Schema({ username: String, password: String, userImg: Object })
const User = mgdb.model('User', UserSchema, 'users')
class UserModel {
    async add({ username, password }) {
        try {
            const obj = new User({ username, password })
            const info = await obj.save()
            return info
        } catch (error) {
            console.log(error)
        }
    }
    async loadImg({ username, userImg }) {
        try {
            let info = await User.find({ username }).exec()
            info[info.length - 1].userImg = userImg
            // console.log(info);
            let newInfo = await info[info.length - 1].save()
            return newInfo.userImg
        } catch (error) {
            console.log(error)
        }
    }
    async findImg({ username }) {
        try {
            let info = await User.find({ username }).exec()
            return info
        } catch (error) {
            console.log(error)
        }
    }
    async check({ username }) {
        try {
            const info = await User.find({ username }).exec()
            return info
        } catch (error) {
            console.log(error)
        }
    }
}
module.exports = UserModel